<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jq/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
	$(function() {
		$("#userName").blur(function() { //当用户名失去焦点时要做的事情
			if ($.trim($(this).val()) == "") { //1、用户名为空时，return
				return;
			}
			$.post("${pageContext.request.contextPath }/user/CheckExists", {
				"user.userName" : $(this).val(),
				"user.pwd" : ""
			}, function(data) { //2、用户名不为空时,判断用户名是否与已注册的重复
				$("[name='isExists']").val(data); //返回信息
				if (data == "1") {
					$("#msg").html("该用户已注册111，请重新输入用户名");
				}
			});
		});
		$("#btn").click(function() {
			if ($.trim($("#userName").val()) == "") {
				$("#msg").html("用户名不能为空");
				return false;
			}
			if ($("[name='isExists']").val() == "1") {
				$("#msg").html("该用户已注册222，请重新输入用户名");
				return false;
			}
			if ($.trim($("#pwd").val()) == "") {
				$("#msg").html("密码不能为空，请输入密码");
				return false;
			}
			return true;
		});
	});
</script>
</head>
<body>
	注册页面
	<br />
	<br />
	<form action="${pageContext.request.contextPath }/user/add.action"
		method="post">
		<table>
			<tr>
				<td width="60">用户名</td>
				<td width="171"><input type="text" name="user.userName"
					id="userName"></td>
			</tr>
			<tr>
				<td>密码</td>
				<td><input type="password" name="user.pwd" id="pwd"></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="提交" id="btn"></td>
			</tr>
		</table>
	</form>
	<input type="hidden" name="isExists" value="0">
	<div id="msg"></div>
	<br />
	<a href="${pageContext.request.contextPath }/main.jsp">返回主页面</a>
</body>
</html>